﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ES.Admin
{
    public partial class YeniKategori : Form
    {
        public int? Id { get; set; }
        public YeniKategori()
        {
            InitializeComponent();
        }
        Category _category = new Category();

        private void YeniKategori_Load(object sender, EventArgs e)
        {
            if (Id.HasValue)
            {
                _category = Program.Db.Categories.SingleOrDefault(d => d.Id == Id.Value);
                if (_category != null)
                {
                    txt_text.Text = _category.Text;
                    txt_seo.Text = _category.SeoText;
                    txt_order.Text = _category.OrderNumber.ToString();
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            _category.Text = txt_text.Text;
            _category.SeoText = txt_seo.Text;
            _category.OrderNumber = short.Parse(txt_order.Text);
            if (!Id.HasValue) { Program.Db.Categories.InsertOnSubmit(_category); }
            Program.Db.SubmitChanges();
            this.Close();
        }
    }
}
